Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better workaround for issue #1187 (warning 40 due to @@deriving sexp) #1188

Merged

Conversation

frank-emrich
Copy link
Contributor

This PR implements a better workaround for #1187.

The previous workaround was to force using an older version of the ppx_sexp_conv, which did not exhibit issue #1187. As such a version constraint may inconvenience users, this PR removes the version constraint and touches the problematic uses of @@deriving sexp directly.

Unforutnately, locally suppressing the warning code 40 triggered by the code generated for @@deriving sexp is somewhat tricky, as there is no AST node in the original source file to attach an ocaml.warning attribute to.

This PR circumvents this problem by wrapping the affected type definitions in an anonymous module, disabling warning 40 within that whole module, and then immediately includeing said module.

This limits the scope in which we actually disable warning 40 to exactly where it is needed.

@frank-emrich
Copy link
Contributor Author

I'm planning to find a better solution for #1187 eventually (e.g., looking into the generated code in detail and reporting a bug with the ppx_sexp_conv authors). In the meantine, this updated workaround is friendlier for end users and should be part of the upcoming Links release (as it avoids forcing users to install an outdated version of ppx_sexp_conv).

@frank-emrich frank-emrich requested a review from dhil October 17, 2023 15:33
lens/column.ml Outdated
Comment on lines 5 to 9
(* Workaround for issue #1187 (i.e., the @@deriving sexp clause on t
below creates code triggering warning 40):
We disable warning 40 within this module, and immediately include it. *)

[@@@ocaml.warning "-40"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better approach is to open the modules in the scope, i.e.

Suggested change
(* Workaround for issue #1187 (i.e., the @@deriving sexp clause on t
below creates code triggering warning 40):
We disable warning 40 within this module, and immediately include it. *)
[@@@ocaml.warning "-40"]
open Sexplib0.Sexp_conv_record.Fields
open Sexplib0.Sexp_conv_record.Kind

This is more robust as it doesn't depend on the OCaml compiler's implicit resolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These particular module paths are not visible from the use sites. I don't fully understand the module structure that Sexplib and Sexplib0 export, but I've now open-ed Sexplib0.Sexp_conv in all the relevant (toplevel) modules instead, and gotten rid of the include struct ... end.

Copy link
Member

@dhil dhil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@frank-emrich frank-emrich force-pushed the ppx_sexp_conv-workaround branch from 6d38f7a to 7ab3429 Compare November 9, 2023 18:25
@frank-emrich frank-emrich merged commit 5bc1d4f into links-lang:master Nov 9, 2023
9 checks passed
@frank-emrich frank-emrich deleted the ppx_sexp_conv-workaround branch November 9, 2023 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants